<?php
  // Make sure an ID was passed
    if(isset($_GET['file_name'])) {
        // Get the ID$id
        $name = $_GET['file_name'];
        // Make sure the ID is in fact a valid ID
    if($name == NULL) {
        // if id is not found
        die('The name is invalid!');
    }
    else {
        // Connect to the database
            $conn = @mysql_connect("localhost" , "root", "") or die(mysql_error());
             mysql_select_db("db_name") or die (mysql_error());
         // get the file information
        $query = "
            SELECT *
            FROM `pdfs`
            WHERE `file_name` = '$name'";
         $result= mysql_query($query) or die(mysql_error());

       
                $row = mysql_fetch_assoc($result);
 
                header("Content-Type: ".$row['type']);
                header("Content-Length: ".$row['size']);
                header("Content-Disposition: inline; filename=". $row['file_name']); 
                // disopsition = attachment to force download request
                // Print data
                readfile($row['data']);
            }
          
        
    
    }
?>
